{template "header.html"}
<script>
    function dr_link_url(id, name) {
        dr_iframe('<i class="fa fa-edit"></i> '+name,'{dr_url(APP_DIR.'/category/link_edit')}&id='+id, '50%', '30%','nogo');
    }
    function dr_content_url(id, name) {
        dr_iframe('<i class="fa fa-edit"></i> '+name,'{dr_url(APP_DIR.'/category/edit')}&isedit=1&page=1&id='+id, '80%', '90%','nogo');
    }
    function dr_cat_field(id, name) {
        dr_iframe('<i class="fa fa-edit"></i> '+name,'{dr_url(APP_DIR.'/category/field_edit')}&id='+id, '50%', '70%', 'nogo');
    }
    // ajax关闭或启用
    function dr_cat_ajax_open_close(e, url, fan) {
        var index = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 10000
        });
        $.ajax({
            type: "GET",
            cache: false,
            url: url,
            dataType: "json",
            success: function (json) {
                layer.close(index);
                if (json.code == 1) {
                    if (json.data.share == 1) {
                        if (json.data.value == fan) {
                            $(e).attr('class', 'badge badge-no');
                            $(e).html('<i class="fa fa-times"></i>');
                        } else {
                            $(e).attr('class', 'badge badge-yes');
                            $(e).html('<i class="fa fa-check"></i>');
                        }
                    } else {
                        // 独立模块 dr_is_page_html
                        var obj = $('.dr_is_page_html');
                        if (json.data.value == fan) {
                            obj.attr('class', 'dr_is_page_html badge badge-no');
                            obj.html('<i class="fa fa-times"></i>');
                        } else {
                            obj.attr('class', 'dr_is_page_html badge badge-yes');
                            obj.html('<i class="fa fa-check"></i>');
                        }
                    }
                    dr_tips(1, json.msg);
                } else {
                    dr_tips(0, json.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);;
            }
        });
    }
    function dr_cat_ajax_save(value, id) {
        var url = "{dr_url($uriprefix.'/displayorder_edit')}&id="+id;
        var index = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 10000
        });
        $.ajax({
            type: "GET",
            cache: false,
            url: url+'&value='+value,
            dataType: "json",
            success: function (json) {
                layer.close(index);
                if (json.code == 1) {
                    dr_tips(1, json.msg);
                } else {
                    dr_tips(0, json.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);;
            }
        });
    }
    // ajax关闭或启用
    function dr_cat_ajax_show_open_close(e, url, fan) {
        var index = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 10000
        });
        var obj = $(e);
        $.ajax({
            type: "GET",
            cache: false,
            url: url,
            dataType: "json",
            success: function (json) {
                layer.close(index);
                if (json.code == 1) {
                    if (json.data.value == fan) {
                        obj.attr('class', 'badge badge-no');
                        obj.html('<i class="fa fa-times"></i>');
                    } else {
                        obj.attr('class', 'badge badge-yes');
                        obj.html('<i class="fa fa-check"></i>');
                    }
                    dr_tips(1, json.msg);
                } else {
                    dr_tips(0, json.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);;
            }
        });
    }
    function dr_tree_data(catid) {
        var index = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 100000
        });
        var value = $(".select-cat-"+catid).html();
        if (value == '[+]') {
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "{dr_url($uriprefix.'/list_index')}&pid="+catid,
                success: function(json) {
                    layer.close(index);
                    if (json.code == 1) {
                        $.ajax({
                            type: "POST",
                            dataType: "json",
                            url: "{dr_url('api/ctotal')}",
                            data: {
                                'cid': json.data,
                                {csrf_token()}: "{csrf_hash()}",
                            },
                            success: function(json2) {
                                if (json2.code == 1) {
                                    eval(json2.msg);
                                }
                            },
                            error: function(HttpRequest, ajaxOptions, thrownError) {
                                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
                            }
                        });
                        $(".dr_catid_"+catid).after(json.msg);
                        $(".select-cat-"+catid).html('[-]');
                        $('.tooltips').tooltip();
                    } else {
                        dr_cmf_tips(json.code, json.msg);
                    }
                },
                error: function(HttpRequest, ajaxOptions, thrownError) {
                    dr_ajax_alert_error(HttpRequest, this, thrownError);
                }
            });
        } else {
            layer.close(index);
            $(".dr_pid_"+catid).remove();
            $(".select-cat-"+catid).html('[+]');
        }
    }
    function dr_scjt() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{dr_url($uriprefix.'/scjt_edit')}",
            data: $("#myform").serialize(),
            success: function(json) {
                if (json.code == 1) {
                    dr_bfb('{dr_lang('生成栏目')}', '', json.msg);
                } else {
                    dr_cmf_tips(json.code, json.msg);
                }

            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);
            }
        });
    }
    function dr_scjt2() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{dr_url($uriprefix.'/scjt2_edit')}",
            data: $("#myform").serialize(),
            success: function(json) {
                if (json.code == 1) {
                    dr_bfb('{dr_lang('生成内容')}', '', json.msg);
                } else {
                    dr_cmf_tips(json.code, json.msg);
                }

            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);
            }
        });
    }
    function dr_update_category_cache() {
        var index = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 10000000
        });
        $.ajax({type: "GET",dataType:"json", url: admin_file+"?c=api&m=update_category_cache&mid={APP_DIR}",
            success: function(json) {
                layer.close(index);
                dr_cmf_tips(json.code, json.msg);
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                layer.closeAll('loading');
                dr_tips(0, "{dr_lang('更新失败，请检查错误日志')}");
            }
        });
    }
    $(function() {
        {if defined('SYS_CAT_POPEN') && SYS_CAT_POPEN}
        {loop $pcats $ii}
        dr_tree_data({$ii});
        {/loop}
        {/if}
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "{dr_url('api/ctotal')}",
                data: {json_encode(['cid'=>$tcats, csrf_token() => csrf_hash()])},
                success: function(json) {
                    if (json.code == 1) {
                        eval(json.msg);
                    }
                },
                error: function(HttpRequest, ajaxOptions, thrownError) {
                    dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
                }
            });
    });

</script>
<style>.dr_total{ font-size: 10px; color:#ccc} </style>
<div class="note note-danger">
    <p><a href="javascript:dr_update_category_cache();">{dr_lang('变更栏目属性之后，需要一键更新栏目配置信息')}</a></p>
</div>

<div class="right-card-box">

    <form class="form-horizontal" role="form" id="myform">
        {dr_form_hidden()}
        <div class="table-scrollable">
            <table class="table table-striped table-bordered table-hover table-checkable dataTable">
                <thead>
                {$cat_head}
                </thead>
                <tbody>
                {$cat_list}
                </tbody>
            </table>
        </div>
        <div class="row fc-list-footer table-checkable ">
            <div class="col-md-12 fc-list-select">
                <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                    <input type="checkbox" class="group-checkable" data-set=".checkboxes" />
                    <span></span>
                </label>
                {if $ci->_is_admin_auth('del')}
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/del')}', '{dr_lang('你确定要删除它们吗？')}', 1)" class="btn red btn-sm"> <i class="fa fa-trash"></i> {dr_lang('删除')}</button></label>
                {/if}
                {if IS_SHARE && $ci->_is_admin_auth('edit') && dr_is_app('chtml')}
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/htmlall_edit')}', '{dr_lang('你确定要批量设置为静态模式吗？')}', 1)" class="btn green btn-sm"> <i class="fa fa-file-o"></i> {dr_lang('静态')}</button></label>
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/phpall_edit')}', '{dr_lang('你确定要批量设置为动态模式吗？')}', 1)" class="btn red btn-sm"> <i class="fa fa-file"></i> {dr_lang('动态')}</button></label>
                {/if}
                {if $ci->_is_admin_auth('edit')}
                <label>{$move_select}</label>
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/move_edit')}', '{dr_lang('你确定要移动它们吗？')}', 1)" class="btn blue btn-sm"> <i class="fa fa-edit"></i> {dr_lang('移动')}</button></label>
                {/if}
                {if dr_is_app('chtml')}
                <label><button type="button" onclick="dr_scjt()" class="btn green btn-sm"> <i class="fa fa-reorder"></i> {dr_lang('生成栏目静态')} </button></label>
                {/if}
            </div>
        </div>
    </form>
</div>

{template "footer.html"}